/**
* @author AlbertDarren
* @contact 2563491540@qq.com
*/
#include <iostream>
#include <ctime>
using namespace std;

int main_28()
{
    int n,S=0,factorial=1;
    const int MOD=1000000;
    scanf("%d",&n);
    for (int i=1; i<=n ; ++i )
    {
        factorial=(factorial*i%MOD);
        S=(S+factorial)%MOD;
    }
    printf("%d\n",S);
    printf("%.4lf\n",(double)clock()/CLOCKS_PER_SEC);
    return 0;
}
